<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbhtbm">
              <a-input v-model="model.dbhtbm" placeholder="请输入担保合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="被担保合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bdbhtbm">
              <a-input v-model="model.bdbhtbm" placeholder="请输入被担保合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保物编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbwbm">
              <a-input v-model="model.dbwbm" placeholder="请输入担保物编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保物类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbwlb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保物类别"
                v-model="model.dbwlb"
                dict="llbb_param_config,name,code"
                pidValue="e5eccc8ac9cf4db2b90c77b0fdeccc64"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="权证编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qzbh">
              <a-input v-model="model.qzbh" placeholder="请输入权证编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否第一顺位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfdysw">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否第一顺位"
                v-model="model.sfdysw"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="评估方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgfs">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择评估方式"
                v-model="model.pgfs"
                dict="llbb_param_config,name,code"
                pidValue="2e7f0ed62d69470eb3b83b15b18c1f23"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="评估方法" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgff">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择评估方法"
                v-model="model.pgff"
                dict="llbb_param_config,name,code"
                pidValue="8c010d80b03e44e19d944cb4d18ef0ba"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="评估价值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgjz">
              <a-input-number v-model="model.pgjz" placeholder="请输入评估价值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="评估基准日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pgjzr">
              <j-date placeholder="请选择评估基准日" v-model="model.pgjzr"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保物票面价值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbwpmjz">
              <a-input-number v-model="model.dbwpmjz" placeholder="请输入担保物票面价值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="优先受偿权数额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yxscqse">
              <a-input-number v-model="model.yxscqse" placeholder="请输入优先受偿权数额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="估值周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzzq">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择估值周期"
                v-model="model.gzzq"
                dict="llbb_param_config,name,code"
                pidValue="1b09d77decd64e568690bed60478a214"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdLoanCollateralInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsCdLoanCollateralInfo/jsCdLoanCollateralInfo/add",
          edit: "/jsCdLoanCollateralInfo/jsCdLoanCollateralInfo/edit",
          queryById: "/jsCdLoanCollateralInfo/jsCdLoanCollateralInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
